Completed
Push — master ( 7403a2...9afade )
by Taavo-Taur
02:16
created

feathers-socket.js ➔ ... ➔ Proto.mixin.setup   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 24
rs 8.9713
1
import Proto from 'uberproto'
2
import socket from 'feathers-socket-commons'
3
import {Server} from './mock-socket'
4
5
/**
6
 * Mocks a connection between client and server
7
 *
8
 * Based on feathers-socketio
9
 *
10
 * @param {String} url
11
 * @returns {Function}
12
 */
13
export default function localSocketer(url) {
14
	return function () {
15
		const app = this
16
17
		app.configure(socket('io'))
18
19
		Proto.mixin({
20
			setup() {
21
				const io = this.io = new Server(url)
22
23
				io.on('connection', socket => {
24
					socket.feathers = {
25
						provider: 'socketio'
26
					}
27
				})
28
29
				this._socketInfo = {
30
					method: 'emit',
31
					connection() {
32
						return io
33
					},
34
					clients() {
35
						return io.clients()
36
					},
37
					params(socket) {
38
						return socket.feathers
39
					}
40
				}
41
42
				return this._super.apply(this, arguments)
43
			}
44
		}, app)
45
	}
46
}
47